package edu.pku.sei.modeler.editparts;

import java.util.List;

import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Text;

public class MessageLabelLocator implements CellEditorLocator {

private final PolylineConnection connection;
	
	public MessageLabelLocator(final PolylineConnection connection) {
		this.connection = connection;
	}

	public void relocate(final CellEditor celleditor) {
		final List<?> children = connection.getChildren();
		final Label label = (Label)children.get(0);
		final Rectangle r = label.getClientArea();
		label.translateToAbsolute(r);
		
		final Text text = (Text)celleditor.getControl();
		org.eclipse.swt.graphics.Rectangle trim = 
			text.computeTrim(r.x, r.y, r.width, r.height);
		
		text.setBounds(trim.x, trim.y, trim.width, trim.height);
	}	

}
